package ctrler

import (
	"reflect"
	"webgo/server/util"
)

var (
	Account AccountType

	store = map[string]any{
		"account": &Account,
	}
)

type Type[CONFIG any] struct {
	config CONFIG
}

func Init() (warn, err error) {

	for _, item := range store {

		_item := reflect.ValueOf(item)

		for _, handle := range []reflect.Value{
			_item.MethodByName("GetConfig"),
			_item.MethodByName("Init"),
		} {
			if err, _ = handle.Call(nil)[0].Interface().(error); err != nil {
				return
			}
		}
	}

	return
}

func Exit() {

}

func (_self *Type[CONFIG]) GetConfig() (err error) {

	return util.GetConfigByEnv(&_self.config)
}
